<?php


namespace app\api\controller;


use app\BaseController;
use app\wechat\controller\AuthBase;
use Composer\Autoload\ClassLoader;
use PHPMailer\PHPMailer\PHPMailer;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use think\App;
use think\console\command\VendorPublish;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;

class Timi
{
    public function update_brand_hot()
    {
        $ip=$_SERVER['REMOTE_ADDR'];
        if ($ip=='127.0.0.1'||$ip=='82.156.114.203') {

            $smoke = Db::name('smoke_record')
                ->whereDay('create_time')
                ->column('smoke_arr');
            $arrs = [];
            foreach ($smoke as $k => $v) {
                $arr = json_decode($v, true);
                $arrs = array_merge($arrs, $arr);
            }
            $smokeIds = array_column($arrs, 'smoke_id');
// 使用 array_count_values 统计每个 smoke_id 出现的次数
            $smokeIdCount = array_count_values($smokeIds);
            foreach ($smokeIdCount as $k => $v) {
                $smoke = Db::name('smoke')
                    ->where('id', $k)
                    ->value('brand_id');
                $brand = Db::name('smoke_brand')
                    ->where('id', $smoke)
                    ->inc('hot', $v)
                    ->update();
            }
        }
    }
    public function update_vip(){
        $ip=$_SERVER['REMOTE_ADDR'];
        if ($ip=='127.0.0.1'||$ip=='82.156.114.203') {
            $res = Db::name('user')
                ->where('vip_end_time', '<', time())
                ->update(['is_vip' => 1]);
            dd($res);
        }
    }
}